package org.cos.verification.verifier;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;

import org.shellex.javame.utility.Screen;

public class CheckReportScreen extends Screen {
	public Form screen = null;
	
	private Command back_cmd;
	private Command save2file_cmd;
	private StringItem app_name;
	private StringItem app_path;
	private StringItem summary;
	
	private static CheckReportScreen instance;
	public static CheckReportScreen getInstance()
	{
		if(instance == null)
			instance = new CheckReportScreen();
		return instance;
	} 
	
	public CheckReportScreen() {
		// TODO Auto-generated constructor stub
	}

	public void crackCommand(MIDlet midlet, Command cmd, Displayable screen) {
		if (cmd == back_cmd) {
			MainScreen.getInstance().display(midlet);
		} else if (cmd == save2file_cmd) {
			;
		}
	}

	public Screen initCommand() {
		back_cmd = new Command("返回主界面", Command.CANCEL, 1);
		save2file_cmd = new Command("保存到文件", Command.SCREEN, 1);
		screen.addCommand(back_cmd);
		screen.addCommand(save2file_cmd);
		return this;
	}

	public Screen initUI(MIDlet midlet) {
		screen = new Form("Cos模型验证报告");
		app_name = new StringItem("应用程序名:", "");
		app_path = new StringItem("程序路径:", "");
		summary = new StringItem("策略统计:", "");
		
		screen.append(new StringItem( 
		"检测完毕。下面请您查阅验证报告: ",null));
		screen.append(app_name);
		screen.append(app_path);
		screen.append(summary);
		screen.append(new StringItem("违反规则:", ""));
		return this;
	}

	public Screen set_summary(String str) {
		summary.setText(str);
		return this;
	}
	
	public Screen add_result(String str, String why){
		screen.append(new StringItem(str, why));
		return this;
	}
	
	public Screen  set_app(String name, String path) {
		this.app_name.setText(name);
		this.app_path.setText(path);
		return this;
	}
	
	
	public void setCommandListener(CommandListener cmdl) {
		screen.setCommandListener(cmdl);
	}

	public void display(MIDlet midlet) {
		Display.getDisplay(midlet).setCurrent(screen);
	}

}
